/*初始化*/
//$(document).ready(function() {
// getzy('0',fg)
// alert(2)
//  
//});
var _getksbaoenname = function(a) {
	for(var b = 0; b < _ksbaonamelist.length; b++) {
		if(a == _ksbaonamelist[b].name) {
			return _ksbaonamelist[b].en
		}
	}
	
	return a
};
var _getksbaoecname = function(a) {
	if(a != null && a.length > 0) {
		for(var b = 0; b < _ksbaonamelist.length; b++) {
			if(_ksbaonamelist[b].en == a) {
				return _ksbaonamelist[b].name
			}
		}
	}
	return null
};

function getUrlParms() {
	
	
	var b = new Object();
	var f = location.search.substring(1);
	var e = f.split("&");
	for(var c = 0; c < e.length; c++) {
		var g = e[c].indexOf("=");
		if(g == -1) {
			continue
		}
		var a = e[c].substring(0, g);
		var d = e[c].substring(g + 1);
		b[a] = decodeURI(d)
	}
	return b
}
var fg = _ksbaonamelist.filter(function (e) { return e.bzy == 'fg'; });
var zpks = _ksbaonamelist.filter(function (e) { return e.bzy == 'zpks'; });
var zg = _ksbaonamelist.filter(function (e) { return e.bzy == 'zg'; });
var wscj = _ksbaonamelist.filter(function (e) { return e.bzy == 'wscj'; });
var wszj = _ksbaonamelist.filter(function (e) { return e.bzy == 'wszj'; });
var zyys = _ksbaonamelist.filter(function (e) { return e.bzy == 'zyys'; });
var ys = _ksbaonamelist.filter(function (e) { return e.bzy == 'ys'; });
var zysy = _ksbaonamelist.filter(function (e) { return e.bzy == 'zysy'; });
var zyhs = _ksbaonamelist.filter(function (e) { return e.bzy == 'zyhs'; });
var yxsc = _ksbaonamelist.filter(function (e) { return e.bzy == 'yxsc'; });
var sj = _ksbaonamelist.filter(function (e) { return e.bzy == 'sj'; });
var ysgp = _ksbaonamelist.filter(function (e) { return e.bzy == 'ysgp'; });
var yskh = _ksbaonamelist.filter(function (e) { return e.bzy == 'yskh'; });
var sbkh = _ksbaonamelist.filter(function (e) { return e.bzy == 'sbkh'; });
var kj = _ksbaonamelist.filter(function (e) { return e.bzy == 'kj'; });
var jz = _ksbaonamelist.filter(function (e) { return e.bzy == 'jz'; });
var jkgls = _ksbaonamelist.filter(function (e) { return e.bzy == 'jkgls'; });

//搜索功能
$("input[type=search]").focus(function(){

	var list='';

	for(var i=0;i<_ksbaonamelist.length-3;i++){
		var w=_ksbaonamelist[i].en;
		var n=_ksbaonamelist[i].name;
		var r=_ksbaonamelist[i].price;
		var d = getProductTypeInfo(w,r);

		var q = d.providers;
		for(var m = 0; m < q.length; m++) {
			var s = q[m];
			
			
			if(d.items[m]) {
				list+='<li kemuName='+_ksbaonamelist[i].name+'>'
				list+='<div class="title_list"><span class="span"> '+w+'</span><span class="a"> '+n+'</span> <i class="icon iconfont icon-jia"></i></div> '
				list+='<div class="content  paylist">'
				list+='<div class="left kemu fl"><span class="span">' + w + '</span><span> '+n+'</span></div>'
				list+='<div class="right paylist fr">'
				for(var k = 0; k < d.items[m].length; k++) {
					var u = d.items[m][k];
					var chuan = n+ u.ver+u.sprice;
   					var prices = u.sprice
				  	list+='<div class="list" cname="'+chuan+'" money="'+prices+'">'
					list+='<input type="checkbox" name="items"  value="'+ u.catid +'" id="items_'+ n+u.catid +'">'
					list+='<label for="items_'+ n+u.catid +'"><span class="km"> '+ u.ver +'</span><span class="cash">'+u.sprice+'</span>元</label>'
					list+='</div>'
//					a++
				 }		
				list+='</div>'
				list+='<div style="clear: both;"></div>'
				list+='</div>'
				list+='</li>'
				

						}
					
					}
				
			}
		
	$('.more_box .right .mao_box').html(list);

	if($("input[type=search]").val==''){
    	$('.more_box .right .mao_box').html(list)
    }
})

function getzy(count,zy){

	var li='';
	li+='<ul class="mao_box hh" id="bookbody">'
	for(var i=0;i<zy.length;i++){
		var w=zy[i].en;
		var n=zy[i].name;
		var r=zy[i].price;
		var nt=zy[i].note;
		var d = getProductTypeInfo(w,r);
//		console.log(d)//专业及课程

		var a = 10;
		var q = d.providers;
		for(var m = 0; m < q.length; m++) {
			var s = q[m];
			
			
			if(d.items[m]) {
				li+='<li>'
				li+='<div class="title_list"><span class="span"> '+w+'</span><span> '+n+'</span> <i class="icon iconfont icon-jia"></i></div> '
				li+='<div class="content  paylist">'
				li+='<div class="left kemu fl"><span class="span">' + w + '</span><span> '+n+'</span></div>'
				li+='<div class="right paylist fr">'
				for(var k = 0; k < d.items[m].length; k++) {
					var u = d.items[m][k];
					var chuan = n + u.ver+u.sprice
					var prices = u.sprice
   					// console.log(u)
				  	li+='<div class="list" cname="'+chuan+'" money='+prices+'>'
					li+='<input type="checkbox" name="items"  value="'+ u.catid +'" id="items_'+ n+u.catid +'">'
					li+='<label for="items_'+ n+u.catid +'" ><span class="km"> '+ u.ver +'</span><span class="cash">'+u.sprice+'</span>元</label>'
					li+='</div>'
					a++
				 }		
				li+='</div>'
				li+='<div style="clear: both;"></div>'
				li+='</div>'
				li+='</li>'
				

						}
					
					}
				
			}
			
	li+='</ul>'	
	// li+= '<div id="pagination" style="margin-top: 10px;height: 35px;">'
	// li+='<a id="firPage" onclick="firstPage(this)" style="margin-left: 0px;width: 35px;">首页</a>'
	// li+='<a id="prePage" >上一页</a>'
	// li+='<a id="nexPage" >下一页</a>'
	// li+='<a id="lasPage"  style="width: 35px;">尾页</a>'
	// li+='<input id="numPage" style="width: 40px;margin-left: 10px;height: 16px;" />'
//     li+='</div>'
	$('.more_box .right').html(li);
	
	

}
function ss(count,zy){
	$('.mao').eq(count).click(function(){
		getzy(count,zy)
	
	})
}
function searchCity() {
        var searchCityName = $("#searchvalue").val();
        console.log(searchCityName)
        if (searchCityName == "") {
            $(".more_box .right .mao_box li").show();
        } else {
        	
            $(".more_box .right .mao_box li").each(
                    function() {
//                      var pinyin = $(this).attr("pinyin");
                        var kemuName = $(this).attr("kemuName");
                        if (
//                      	pinyin.indexOf(searchCityName) != -1||
                        kemuName.indexOf(searchCityName) != -1) {
                            $(this).show();
                        } else {
                             $(this).hide();
							
                        }
                    });
					 // if($(".more_box .right .mao_box li").is(":hidden")){
	// $('.more_box .right').html("<p>没查到相关信息，请关注niukebaodian公众号</p>")
   // }
        }
    }
	 
 
    $("#searchvalue").bind('input propertychange', function() {
 
        searchCity();
    });
/* $("input[type=search]").change(function () {
   
    var searchText = $(this).val();//获取输入的搜索内容
    var $searchLi = "";//预备对象，用于存储匹配出的li
    
    if (searchText != "") {
     //获取所有匹配的li
     
//   console.log($("more_box .right").find('span:contains('+ searchText +')').parent())
     $searchLi = $(".more_box .right .mao_box").find('.a:contains('+ searchText +')').parents('li');
//   console.log($searchLi)
     
     
     //将内容清空
     $(".more_box .right .mao_box").html("");
     
    $(".more_box .right .mao_box").html($searchLi).clone();
    }
    //将获取的元素追加到列表中
   
    //判断搜索内容是否有效，若无效，输出not find
    
    if ($searchLi.length <= 0) {
     $(".more_box .right").html("<li>没查到相关信息，请关注niukebaodian公众号</li>")
    }
     
   }) */


   $(".searchbtn").click(function () {
   	
   	
    $("searchText").change();
    
   })
getzy('1',zg)
getzy('2',wscj)
getzy('3',wszj)
getzy('4',zyys)
getzy('5',ys)
getzy('6',zysy)
getzy('7',zyhs)
getzy('8',sj)
getzy('9',ysgp)
getzy('10',yskh)
getzy('11',sbkh)
getzy('12',zpks)
getzy('13',yxsc)
getzy('14',kj)
getzy('15',jz)
getzy('16',jkgls)
getzy('0',fg)
ss('0',fg)

ss('1',zg)
ss('2',wscj)
ss('3',wszj)
ss('4',zyys)
ss('5',ys)
ss('6',zysy)
ss('7',zyhs)
ss('8',sj)
ss('9',ysgp)
ss('10',yskh)
ss('11',sbkh)
ss('12',zpks)
ss('13',yxsc)
ss('14',kj)
ss('15',jz)
ss('16',jkgls)
function initpayli() {
	
	var c = getUrlParms();
	var w = c.name;
	var r = c.price;
	var e = c.tel;
	
	if(!w || w == "") {
		w = c.aliorder
	}
	if(w == null || typeof(w) == "undefined") {
		w = ""
	}
	if(!r || r == "") {
		r = c.alimoney
	}
	if(!e || e == "") {
		e = c.UserName
	}
	if(w) {
		try {
			w = decodeURI(w)
		} catch(f) {
			console.log("decodeURI err")
		}
	}
	if(e && e != "") {
		$("#mob").val(e)
	}
	var n = c.UserName;
	var g = c.aliorder;
	var v = c.alimoney;
	if(n && g && v) {
		var l = g;
		if(l.indexOf("_") == -1) {
			l = _getksbaoenname(l)
		}
		var h = '{"UserName":"' + n + '","aliorder":"' + l + '","alimoney":"' + v + '"}';
		$("#userMessage").val(h)
	}
	
	var d = getProductTypeInfo(w, r);
	
	if(d && d.items[0].length > 0) {
		var a = 1000;
		var q = d.providers;
		var i = "";
		var j = '<p  style="color:red">\u73ed\u6b21\u8bf4\u660e\uff1a</p>';
		var o = w;
		
		if(o.indexOf("_") > 0) {
			o = _getksbaoecname(w)
			
		}
		if(o == null || o.length < 1) {
			o = w
		}
		str=''
		for(var m = 0; m < q.length; m++) {
			var s = q[m];
			console.log(s)
			if(d.items[m]) {
				var b = o + s;
				console.log(o)
				 
				str+=	'<li style="border-bottom:1px solid #DEDFE0">'
				str+='<p class="kemu">' + b +'</p>'
				if(d.notes != undefined && d.notes[0].length > 2) {
					str+=		'<p align=left style="padding-left: 30px;">('+ d.notes[0] +')</p>'

				}

						str+=	'</li>'
						str+=	'<li class="paylist">'
				for(var k = 0; k < d.items[m].length; k++) {
					var u = d.items[m][k];
                    var chuan = o + u.ver+u.sprice
					var prices = u.sprice
					j += '<div class="note_items"><p ><i> ' + u.ver + "\uff1a</i><span> " + u.note + "</span> </p></div>";
					str+='<div class="lii" cname="'+chuan+'" money="'+prices+'">'
					str+='<input type="checkbox" name="items"  value="' + u.catid +'" id="items_' + u.catid +'">'
					str+='<label for="items_' + u.catid +'" ><i class="km"> '+ u.ver +'</i> <span class="cash"> '+u.sprice+'</span>元</label>'
					str+='<div class="pc_note"> ' + u.note + '</div>'
					str+= '</div>'
					a++
				}
				str+=	'</li>'
				str+='<div style="clear: both;"></div>'

			}

		}

		$(".buy_box>.hh").html(str);

	}

}
initpayli();

